Repository navigation
fix(id-web): reject malformed bracketed IPv6 Host authorities (#8776) - #8797
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 7 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5be8434eec
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for malformed in [ | ||
| "[::1]attacker.example", | ||
| "[::1]attacker.example:3000", | ||
| "[::1]:abc", | ||
| "[::1]:", |
There was a problem hiding this comment.
Cover the authority parser invariant with property-based tests
The new test states a meaningful parser invariant—malformed bracketed authorities must not collapse to an allowed host—but checks only six fixed examples. Root AGENTS.md explicitly requires property-based coverage for parser invariants, and proptest is already a dev-dependency of this package. Add generated valid authorities and malformed suffix/delimiter variants to check the invariant, retaining these examples as regression smoke tests.
AGENTS.md reference: AGENTS.md:L42-L42
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in follow-up commit c72d639 on this branch: added a proptest block in web::security::tests covering the invariant directly —
bracketed_authority_collapses_only_for_valid_tails: generated hosts (::1,::,fe80::1,2001:db8::1) × generated printable-ASCII tails (0–12 chars); the oracle restates the invariant —host_onlyreturns the bracketed host only when the tail is empty or:+ a non-empty all-digit port, and never otherwise. The six fixed examples stay as regression smoke tests and are referenced as such.bracketed_authority_with_numeric_port_always_extracts_host: generatedu16ports always extract the host, as does the bare bracketed form.
Verified in the probe harness that compiles the real security.rs (the in-tree lib target is blocked by the pre-existing #8795 compile breakage): 21/21 tests pass, including both new properties at 128 cases.
Fixes #8776. Queue task 15033 (lane code-a).
The bug
host_onlyinpkgs/id/src/web/security.rshandled any authority starting with[by returning the text before the first], without validating the remainder. The loopback Host guard then compared only that prefix againstallowed_hosts, soHost: [::1]attacker.examplereduced to::1and passed the loopback allow-list — as did the unterminated[::1.The fix
host_onlynow validates the complete bracketed authority before extracting the host: only an empty tail or a:+ numeric port may follow the closing bracket. A malformed bracketed authority (trailing host text, non-numeric or empty port, missing closing bracket) returns the full authority text, which matches no allowed host, so the guard refuses it withMISDIRECTED_REQUEST(421). Scope is confined tohost_only; no Origin-parsing changes.Tests
Two regression tests added in
web::security::tests:host_only_rejects_malformed_bracketed_authorities— malformed forms ([::1]attacker.example,[::1]attacker.example:3000,[::1]:abc,[::1]:,[::1,[::1]]) must not reduce to::1; valid[::1]and[::1]:3000still extract::1.malformed_bracketed_host_is_refused— the guarded router returns 421 for malformed bracketed hosts and 200 for the valid controls.Verification note (pre-existing breakage)
The
pkgs/idlib does not compile on current main with the web feature (5 pre-existing errors insrc/web/routes.rs,explore.rs,world_ws.rs— crate-split visibility fallout, proven identical on a pristine worktree of e6889a3 and filed as #8795), so the in-tree lib tests cannot run yet. The tests above were therefore run in a probe harness that compiles the realsecurity.rsby path:[::1]attacker.examplegot 200 instead of 421;host_onlyreturned::1), the other 17 security tests pass.cargo check -p id --lib --all-featureson this branch reports exactly the same 5 pre-existing errors as pristine main — no new errors, none insecurity.rs.rustfmt --checkon the file is clean.Once #8795 lands, these tests run in-tree with the rest of the
web::securitysuite.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.